<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增模板</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../lib/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/jquery.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script type="text/javascript" src="../js/commonutil.js"></script>
    <script src="./function.js" charset="utf-8"></script>
</head>
<body>
<div class="edit-form-class" style="padding-top: 20px;">
    <form class="layui-form" id="editForm">
        <div class="layui-form-item">
            <label class="layui-form-label">模板编码</label>
            <div class="layui-input-block">
                <input type="text" id="templateNo" name="templateNo" readonly="readonly" style="width: 350px" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板名称</label>
            <div class="layui-input-block">
                <input type="text" id="templateName" name="templateName" lay-verify="required|templateNameVerify"  style="width: 350px" autocomplete="off" placeholder="" class="layui-input">
                <input type="text" id="id" name="id" style="display:none;"  autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板文件</label>
            <div class="layui-input-block" style="padding-top: 5px">
                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-btn-radius" id="uploadFile">上传文件</button>
                <input id='templateExtId' name='templateExtId' type="text" class="text" maxlength='50' style='display:none;'/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">签章类型</label>
            <div class="layui-input-block" style="width: 350px">
                <select name="sealType" id="sealType" lay-verify="required|sealTypeVerify">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板渠道</label>
            <div class="layui-input-block" style="width: 350px">
                <select name="channelId" id="channelId" lay-verify="required|channelIdVerify">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公章规则</label>
            <div class="layui-input-block" style="width: 350px">
                <input type="text" id="officialSealId" name="officialSealId" lay-verify="required|officialSealId" style="width: 350px" placeholder="多个用逗号分隔(请使用半角,)" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block" style="padding-top: 7px">
                <input type="checkbox" checked="checked" name="templateStatus" id="templateStatus" lay-skin="switch" lay-text="启用|禁用">
                <input type="text" id="version" name="version"  style="display:none;"  autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" autocomplete="off" lay-filter="submitBtn" id="submitBtn">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>

<script>
    jQuery(function(){
        layui.use(['laypage','jquery', 'layer', 'table', 'form', 'util','upload'], function(){
            let table = layui.table;
            let laypage = layui.laypage;
            let layer = layui.layer;
            let form = layui.form;
            let  util = layui.util;
            let $ = layui.jquery;
            let upload = layui.upload;

            //初始化渠道
            queryChannels(form);
            //初始化签章类型
            querySealType(form);
            //初始化数据
            buildEditWin(form);

            //文件上传
            let uploadUrl = serverPre + "/manager/scs/v2/template/upload";
            uploadFile(upload,uploadUrl);
            form.render();
        });
    });

    //提交
    $('#submitBtn').click(function () {
        let url = serverPre + "/manager/scs/v2/template/update";
        let formData = serializeObject($("#editForm"));
        let commitData = JSON.stringify({"id":formData.id,"version":formData.version,"templateNo":formData.templateNo,"templateName":formData.templateName,"refId":formData.templateExtId,"sealType":formData.sealType,"channelId":formData.channelId,"officialSealId":formData.officialSealId,"templateStatus":formData.templateStatus === 'on' ? 1 : 0});
        submitForm(commitData,url);
    });
</script>
</html>
